package mysql

import "gorm.io/gorm"

type Goods struct {
	gorm.Model
	GoodsTitle  string  `gorm:"type:varchar(20);not null;comment:'商品名称'"`
	GoodsNum    int64   `gorm:"type:int;default:0;comment:'商品数量'"`
	GoodsImage  string  `gorm:"type:varchar(225);not null;comment:'商品图标'"`
	GoodsPrice  float64 `gorm:"type:decimal(10,2);default:0.00;comment:'商品费用'"`
	GoodsLike   int64   `gorm:"type:int;default:0;comment:'点赞数量'"`
	GoodsStatue int64   `gorm:"type:tinyint(1);default:1;comment:'审核商品:0-审核中、1-审核通过、2-审核不通过'"`
}

func (g *Goods) Find(GoodsStatue, Page, pageSize int64) (list []*Goods, err error) {
	if GoodsStatue == 0 {
		err = DB.Offset(int((Page - 1) * pageSize)).Limit(int(pageSize)).Find(&list).Error
		return
	} else {
		err = DB.Where("goods_statue =?", GoodsStatue).Offset(int((Page - 1) * pageSize)).Limit(int(pageSize)).Find(&list).Error
		return
	}
}

func (g *Goods) Update(GoodsStatue int64) error {
	return DB.Model(&g).Update("goods_statue", GoodsStatue).Error
}

func (g *Goods) Create() error {
	return DB.Create(&g).Error
}
